home *** CD-ROM | disk | FTP | other *** search
- Path: frco.com!usenet
- From: Jadam@tcmail.frco.com (Jim Adam)
- Newsgroups: comp.lang.c++
- Subject: Re: Help!! I'm a stuck newbie - input problem
- Date: 2 Feb 1996 19:30:05 GMT
- Organization: Fisher Rosemount Systems
- Distribution: world
- Message-ID: <4etont$6gn@rolaids.frco.com>
- References: <4eh3vl$g8i@atlas.uniserve.com>
- NNTP-Posting-Host: primrose.frco.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.11
-
- In article <4eh3vl$g8i@atlas.uniserve.com>, nowher@anyplace.com says...
-
- >Presently, I have the following variables declared:
-
- >char TempStr[20];
- >char ch;
- >int x=0;
-
- >I need to input a string with a max length of 15 chars.
- >( I need to fill the database fields: Part Number:[ ] )
-
- >I do not want to overwrite the bracket on the right of the field. I have
- >tried various methods, but I get errors, or it otherwise doesn't do what
- >I need it to.
-
- Chris,
-
- Can you explain your problem some more? I.e., are you having trouble
- reading the string (from a file? from standard input?) or are
- you having trouble outputting it (to a string? to the screen?).
-
- Anyway, here's one approach using the standard input and output
- streams. This assumes the part number your getting on a line by itself.
-
- void getPartNumber( istream& istr, char * buffer, size_t bufSize )
- {
- istr.getline( buffer, bufSize );
- }
-
- void writePartNumber( ostream & ostr, const char * number )
- {
- char oldFill = ostr.fill( ' ' );
- ostr << "Part Number:[" << setw(15) << number << ']' << endl;
- ostr.fill( oldFill );
- }
-
- void main( void )
- {
- char buffer[20];
- getPartNumber( cin, buffer, sizeof(buffer));
- writePartNumber( cout, buffer );
- }
-
- Jim
-
-